import { createWebHistory, createRouter } from 'vue-router';

export const constantRoutes = [
  {
    path: '/',
    name: 'INDEX',
    component: () => import('@/views/login.vue'),
  },
  {
    path: '/login',
    name: 'LOGIN',
    component: () => import('@/views/login.vue'),
  },
  {
    path: '/chat',
    name: 'CHAT',
    component: () => import('@/views/chat/index.vue'),
  },
  {
    path: '/chatMsg',
    name: 'CHAT_MSG',
    component: () => import('@/views/chatMsg/index.vue'),
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
  },
  {
    path: '/:pathMatch(.*)*',
    component: () => import('@/views/error/404'),
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  },
});

export default router;
